
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import Command
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    
    urdf_path = get_package_share_directory('robot_description')+'/urdf/arm_gazebo.xacro'
    
    config_file_path = get_package_share_directory('robot_description')+'/config/display_model.rviz'
    
    robot_desc = Command([f'xacro {urdf_path}'])
    
    # node
    state_publisher = Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher',
            output='screen',
            parameters=[{
                'robot_description': robot_desc 
            }],
        )
    
    # joint_state_publisher
    joint_state_publisher = Node(
            package="joint_state_publisher",
            executable="joint_state_publisher",
            # parameters=[
            #     { 'source_list' : ['/joint_state_broadcaster/joint_states']}
            # ],
            output="screen",
        )
    
    # rviz
    rviz = Node(
            package='rviz2',
            executable='rviz2',
            output='screen',
            name='rviz2',
            # 这里一定要分开
            arguments=["-d", config_file_path]
        )
                    

    return LaunchDescription([
        state_publisher,
        joint_state_publisher,
        rviz
    ])
